package com.lxb.myforum.repository


import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.PagingAndSortingRepository
import org.springframework.stereotype.Repository

import com.lxb.myforum.pojo.Authority

/**
 *
 * @author lxb
 */
@Repository
interface AuthorityRepository : PagingAndSortingRepository<Authority, Long>, JpaSpecificationExecutor<Authority> {
    // SELECT * FROM t_authority AS a RIGHT OUTER JOIN t_role_authority AS b ON a.id = b.authority_id WHERE b.role_id != 1;
    //	List<Authority> findAuthByRoleId();

    @Query(
            value = "select * from `t_authority` a left join `t_role_authority` b on a.id = b.`authority_id` where b.role_id != ?1 || ISNULL(b.role_id);",
            nativeQuery = true
    )
    fun findNotRoleAuthorities(roleId: Long): List<Authority>
}
